require(["dojo/dom", 
         "dojo/request", 
         "dojo/_base/array", 
         "dojo/domReady!" ], 
		function(dom, request, arrayUtil){
	
	var results=dom.byId("results");
	
	gotDistrib=function(data){
		dom.byId("stock"+data.split(":")[0]).innerHTML=data.split(":")[1]+":"+data.split(":")[2]+":"+data.split(":")[3];
	};
	
	failedDistrib=function(error){
		results.innerHTML="Error occured getting distribution: "+error;
	};
	
	processItem=function(item){
		results.innerHTML+="<BR><SPAN ID=stock"+item.id+">"+item.name+"</SPAN>";
		request.get("/FinanceWeb/Distribution?id="+item.id,gotDistrib,failedDistrib);
	};
	
	failedStocks=function(error){
		results.innerHTML="Error occured during available stock fetch: "+error;
	};
	
	gotStocks=function(data){
		arrayUtil.forEach(data.items,processItem);
	};
	
	request.get("/FinanceWeb/JsonStockList", {handleAS: "json"}).then(gotStocks,failedStocks);
	
	popSelect.startup();
	stockSelect.startup();
	
});